package nakedb;


import nakedb.NakeDB.LayoutName;
import prefuse.action.ActionList;
import prefuse.action.RepaintAction;
import prefuse.action.layout.Layout;
import prefuse.activity.Activity;

/**
 * Layout manager for NakeDB.
 */
public class LayoutInfo {
  private LayoutName name;
  private ActionList actionList;
  private Layout layout;
  private RepaintAction repaintAction;
  
  private boolean repaintActionOn;
  
  public LayoutInfo(LayoutName name, Layout layout) {
    this.name = name;
    this.layout = layout;
    this.actionList = new ActionList(Activity.INFINITY); //50
    this.repaintAction = new RepaintAction();

    actionList.add(layout);
    actionList.add(new AggregateLayout(NakeDB.AGGR));
    repaintActionOn = false;
    addRepaintAction();
  }
  
  public ActionList getActionList() {
    return actionList;
  }
  
  public RepaintAction getRepaintAction() {
    return repaintAction;
  }

  public LayoutName getName() {
    return name;
  }
  
  public void removeRepaintAction() {
    actionList.remove(repaintAction);
    repaintActionOn = false;
  }
  
  public void addRepaintAction() {
    if (!repaintActionOn) {
      actionList.add(repaintAction);
      repaintActionOn = true;
    }
  }
  
  public void setDurationInfinity() {
    if (actionList.getDuration() != ActionList.INFINITY) {
      actionList.setDuration(ActionList.INFINITY);
      actionList.run();
    }
  }
  
  public void setDurationNonInfinity() {
    actionList.setDuration(2000);
  }
  
  public boolean hasRepaintActionOn() {
    return repaintActionOn;
  }

  public Layout getLayout() {
    return layout;
  }
  
  
}
